home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / Telephone Manager / Stiletto Sources / Sources / Stiletto.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-04  |  24.4 KB  |  1,009 lines  |  [TEXT/MPS ]

  1. /************************************************************************************************/
  2. /*                                                                                                */
  3. /*    Program Name:    Stiletto                                                                    */
  4. /*                                                                                                */
  5. /*    File Name:        Stiletto.c                                                                    */
  6. /*                                                                                                */
  7. /*    © Apple Computer, Inc. 1991-1995                                                            */
  8. /*    All Rights Reserved                                                                            */
  9. /*                                                                                                */
  10. /*    Revision History:                                                                            */
  11. /*                                                                                                */
  12. /*        Date        Who                    Modification                                            */
  13. /*                                                                                                */
  14. /*        1991-06-30    Chris Halim            Original version                                        */
  15. /*        1995-06-26    Jaakko Railo        Version 2.0                                                */
  16. /*                                                                                                */
  17. /************************************************************************************************/
  18.  
  19. /****************************************** DESCRIPTION ******************************************
  20.  
  21. *************************************************************************************************/
  22.  
  23. /******************************************** HEADERS *******************************************/
  24.  
  25. #include "Aliases.h"
  26. #include "Desk.h"
  27. #include "DiskInit.h"
  28. #include "FCntl.h"
  29. #include "Gestalt.h"
  30. #include "Resources.h"
  31. #include "SegLoad.h"
  32. #include "string.h"
  33. #include "Strings.h"
  34. #include "ToolUtils.h"
  35. #include "Traps.h"
  36.  
  37. #include "Telephones.h"
  38.  
  39. #include "About.h"
  40. #include "CAHandlers.h"
  41. #include "Constants.h"
  42. #include "DNHandlers.h"
  43. #include "Init.h"
  44. #include "LogWindow.h"
  45. #include "ModuleWindow.h"
  46. #include "Preferences.h"
  47. #include "Stiletto.h"
  48. #include "TermWindow.h"
  49. #include "TestModule.h"
  50. #include "Utilities.h"
  51.  
  52. /****************************************** DEFINITIONS *****************************************/
  53.  
  54. static AEHandlerStructure keywordsToInstall[] = {
  55.     { kCoreEventClass,        kAEOpenApplication,        (ProcPtr) DoAEOpenApplication },
  56.     { kCoreEventClass,        kAEOpenDocuments,        (ProcPtr) DoAEOpenDocuments },
  57.     { kCoreEventClass,        kAEPrintDocuments,        (ProcPtr) DoAEPrintDocuments },
  58.     { kCoreEventClass,        kAEQuitApplication,        (ProcPtr) DoAEQuitApplication }
  59. };
  60.  
  61. /****************************************** PROTOTYPES ******************************************/
  62.  
  63. /******************************************** GLOBALS *******************************************/
  64.  
  65. Boolean            gInBackground     = false;
  66. Boolean            gQuit            = false;
  67.  
  68. LogWindowPtr    gLogWindow        = nil;
  69. TelWindowPtr    gTelWindow        = nil;
  70. ModuleWindowPtr    gModuleWindow    = nil;
  71.  
  72. TELCAHandle        gAvailableCA    = nil;
  73.  
  74. extern    TelephoneCAMsgUPP        gAllCAMsgsHandlerUPP;
  75. extern    TelephoneDNMsgUPP        gAllDNMsgsHandlerUPP;
  76. extern    TelephoneTermMsgUPP        gAllTermMsgsHandlerUPP;
  77.  
  78. extern    TelephoneTermMsgUPP        gTermMsgHandlerUPP;
  79.  
  80. #ifdef __powerc
  81. QDGlobals        qd;
  82. #endif
  83.  
  84. /************************************************************************************************/
  85. /************************************************************************************************/
  86.  
  87.  
  88. /**
  89.  **        This routine is part of the MPW runtime library. We need an external reference
  90.  **        to it, so that we can unload its segment (%A5Init) early in the program.
  91.  **/
  92.  
  93. extern void _DataInit();
  94.  
  95.  
  96. #pragma segment Main
  97. void Terminate (void)
  98. {
  99.     //
  100.     //    If we have any open document that needs to be saved to disk,
  101.     //        this is the place to ask if user wants to save open files.
  102.     //    IMPORTANT : if cancel is chosen, DO NOT quit !!!
  103.     //
  104.  
  105.     TELHandle    termHand;
  106.     OSErr        errCode;
  107.         
  108.     SaveWinLocToPref ((WindowPtr) gLogWindow, rLogWindRECT);
  109.     SaveWinLocToPref ((WindowPtr) gTelWindow, rTelWindRECT);
  110.     SaveWinLocToPref ((WindowPtr) gModuleWindow, rModuleWindRECT);
  111.     
  112.     termHand = gTelWindow->fTELHandle;
  113.  
  114.     DisposeTelWindow (gTelWindow);
  115.  
  116.     if ((errCode = TELClrTermMsgHand (termHand, gTermMsgHandlerUPP)) != noErr)
  117.         PutCLine (gLogWindow, kErrorColor, "### TELClrTermMsgHand failed : %d", errCode);
  118.         
  119.     if ((errCode = TELCloseTerm (termHand)) != noErr)
  120.         PutCLine (gLogWindow, kErrorColor, "### TELCloseTerm failed : %d", errCode);
  121.  
  122.     if ((errCode = TELDispose (termHand)) != noErr)
  123.         PutCLine (gLogWindow, kErrorColor, "### TELDispose failed : %d", errCode);
  124.  
  125.     DisposeModuleWindow (gModuleWindow);
  126.  
  127.     gQuit = true;
  128. }
  129.  
  130.  
  131. #pragma segment Initialize
  132. void    InitializedAppleEvents (void)
  133. {
  134.     OSErr                errCode;
  135.     short                i;
  136.     AEEventHandlerUPP    theAEEventHandlerUPP;
  137.  
  138.     for (i = 0; i < (sizeof(keywordsToInstall) / sizeof(AEHandlerStructure)); ++i) {
  139.         theAEEventHandlerUPP = NewAEEventHandlerProc (keywordsToInstall[i].theHandler);
  140.         if (theAEEventHandlerUPP != NULL) {
  141.             errCode = AEInstallEventHandler(
  142.                 keywordsToInstall[i].theEventClass,    /* What class to install.  */
  143.                 keywordsToInstall[i].theEventID,    /* Keywords to install.    */
  144.                 theAEEventHandlerUPP,                /* The AppleEvent handler. */
  145.                 0L,                                    /* Unused refcon.           */
  146.                 false                                /* Only for our app.       */
  147.             );
  148.             
  149.             if (errCode)
  150.                 PutLine (gLogWindow, "### AEInstallEventHandler fails : ", errCode);
  151.         }
  152.         else
  153.             PutLine (gLogWindow, "### NewAEEventHandlerProc failed : ", MemError());
  154.     }
  155. }
  156.  
  157.  
  158. #pragma segment Main
  159. void    AdjustMenus (void)
  160. {
  161.     MenuHandle    aMenu1, aMenu2;
  162.     long        windRefCon = GetWRefCon (FrontWindow ());
  163.     short        item;
  164.     
  165.     aMenu1 = GetMHandle (rFileMenu);
  166.     if (FrontWindow())
  167.         EnableItem (aMenu1, iClose);
  168.     else
  169.         DisableItem (aMenu1, iClose);
  170.  
  171.     aMenu1 = GetMHandle (rEditMenu);            // At this stage of the program, we are
  172.     DisableItem (aMenu1, iUndo);                //      not implementing edit capabilities.
  173.     DisableItem (aMenu1, iCut);
  174.     DisableItem (aMenu1, iCopy);
  175.     DisableItem (aMenu1, iPaste);
  176.     DisableItem (aMenu1, iClear);
  177.     
  178.     aMenu1 = GetMHandle (rInfoMenu);
  179.     for (item = iDumpCAState; item <= iDumpTermEvents; ++ item)
  180.         DisableItem (aMenu1, item);
  181.     
  182.     aMenu2 = GetMHandle (rHandlerMenu);
  183.     for (item = iInstallAllCA; item <= iRemoveAllTerm; ++ item)
  184.         DisableItem (aMenu2, item);
  185.     
  186.     switch (windRefCon) {
  187.         case rCAWIND :
  188.             EnableItem (aMenu1, iDumpCAState);
  189.             EnableItem (aMenu1, iDumpCAInfo);
  190.             EnableItem (aMenu1, iDumpCAEvents);
  191.             EnableItem (aMenu1, iDumpCAFlags);
  192.             break;
  193.             
  194.         case rDNWIND :
  195.             EnableItem (aMenu1, iDumpDNInfo);
  196.             EnableItem (aMenu1, iDumpDNEvents);
  197.             EnableItem (aMenu1, iDumpDNFlags);
  198.             
  199.             EnableItem (aMenu2, iInstallAllCA);
  200.             EnableItem (aMenu2, iRemoveAllCA);
  201.             
  202.             EnableItem (aMenu2, iInstallAllDN);
  203.             EnableItem (aMenu2, iRemoveAllDN);
  204.             break;
  205.             
  206.         case rTelWIND :
  207.             EnableItem (aMenu1, iDumpTermInfo);
  208.             EnableItem (aMenu1, iDumpTermEvents);
  209.             
  210.             EnableItem (aMenu2, iInstallAllTerm);
  211.             EnableItem (aMenu2, iRemoveAllTerm);
  212.             break;
  213.     }
  214. }
  215.  
  216.  
  217. #pragma segment Main
  218. void LoopTheLoop (void)
  219. {
  220.     EventRecord    theEvent;
  221.     RgnHandle    cursorRgn;
  222.     Boolean        gotEvent;
  223.     
  224.     cursorRgn    = NewRgn ();            // We don't have any specialized cursor in this
  225.                                         //      app. so pass NIL to WaitNextEvent ().
  226.     while (!gQuit)                        // Keep checking the event queue until user 
  227.     {                                    //    wants to quit.
  228.         
  229.         gotEvent = WaitNextEvent (everyEvent, &theEvent, SleepVal(), cursorRgn);
  230.         
  231.         if (! IsHandledByModuleWindow (gModuleWindow, &theEvent))
  232.         {
  233.             if (! IsHandledByTelWindow (gTelWindow, &theEvent))
  234.             {
  235.                 if (! IsHandledByLogWindow (gLogWindow, &theEvent))
  236.                 {
  237.                     if (gotEvent)
  238.                         HandleEvent (&theEvent);
  239.                     else
  240.                         DoIdle ();
  241.                 }
  242.             }
  243.         }
  244.     }
  245. }
  246.  
  247.  
  248. #pragma segment Main
  249. unsigned long SleepVal(void)
  250. {
  251.     unsigned long sleep;
  252.     const long kSleepTime = 0x00;    // we want to be called as often as possible
  253.  
  254.     sleep = kSleepTime;                // default value for sleep
  255.     if ((!gInBackground))
  256.     {
  257.           sleep = GetCaretTime();
  258.     }
  259.     return sleep;
  260. }
  261.  
  262.  
  263. #pragma segment Main
  264. void    DoIdle (void)
  265. {
  266. }
  267.  
  268.  
  269. #pragma segment Main
  270. void HandleEvent(const EventRecord    *theEvent)
  271. {
  272.     short        err;
  273.     char        key;
  274.     Point        aPoint;
  275.         
  276.     switch ( theEvent->what ) {
  277.         case nullEvent :
  278.             DoIdle ();
  279.             break;
  280.             
  281.         case mouseDown :
  282.             DoMouseDown (theEvent);
  283.             break;
  284.             
  285.         case mouseUp:
  286.             DoMouseUp (theEvent);
  287.             break;
  288.             
  289.         case keyDown:
  290.         case autoKey:
  291.             key = theEvent->message & charCodeMask;
  292.             if ( theEvent->modifiers & cmdKey )    {        // Command key is down
  293.                 if ( theEvent->what == keyDown ) {
  294.                     AdjustMenus();
  295.                     DoMenuCommand(MenuKey(key), theEvent->modifiers);
  296.                 }
  297.             } else {
  298.                 switch (key) {
  299.                     case 'c' :
  300.                         PutLine (gLogWindow, "Tyger! Tyger! burning bright");
  301.                         PutLine (gLogWindow, "In the forests of the night,");
  302.                         PutLine (gLogWindow, "What immortal hand or eye");
  303.                         PutLine (gLogWindow, "Could frame thy fearful symmetry?");
  304.                         PutLine (gLogWindow, "");
  305.                         PutLine (gLogWindow, "In what distant deeps or skies");
  306.                         PutLine (gLogWindow, "Burnt the fire of thine eyes?");
  307.                         PutLine (gLogWindow, "On what wings dare he aspire?");
  308.                         PutLine (gLogWindow, "What the hand, dare seize the fire?");
  309.                         PutLine (gLogWindow, "");
  310.                         PutLine (gLogWindow, "And what shoulder, & what art,");
  311.                         PutLine (gLogWindow, "Could twist the sinews of thy heart?");
  312.                         PutLine (gLogWindow, "And when thy heart began to beat,");
  313.                         PutLine (gLogWindow, "What dread hand? & what dread feet?");
  314.                         PutLine (gLogWindow, "");
  315.                         PutLine (gLogWindow, "What the hammer? what the chain?");
  316.                         PutLine (gLogWindow, "In what furnace was thy brain?");
  317.                         PutLine (gLogWindow, "What the anvil? what dread grasp");
  318.                         PutLine (gLogWindow, "Dare its deadly terrors clasp?");
  319.                         PutLine (gLogWindow, "");
  320.                         PutLine (gLogWindow, "When the stars threw down their spears,");
  321.                         PutLine (gLogWindow, "And water'd heaven with their tears,");
  322.                         PutLine (gLogWindow, "Did he smile his work to see?");
  323.                         PutLine (gLogWindow, "Did he who made the Lamb make thee?");
  324.                         PutLine (gLogWindow, "");
  325.                         PutLine (gLogWindow, "Tyger! Tyger! burning bright");
  326.                         PutLine (gLogWindow, "In the forests of the night,");
  327.                         PutLine (gLogWindow, "What immortal hand or eye");
  328.                         PutLine (gLogWindow, "Dare frame thy fearful symmetry?");
  329.                         PutLine (gLogWindow, "");
  330.                         PutLine (gLogWindow, "                 William Blake, 1794");
  331.                         PutLine (gLogWindow, "");
  332.                         break;
  333.                 }
  334.             }
  335.             break;
  336.             
  337.         case activateEvt:
  338.             DoActivate ((WindowPtr) theEvent->message, (theEvent->modifiers & activeFlag) != 0);
  339.             break;
  340.             
  341.         case updateEvt:
  342.             DoUpdate (theEvent);
  343.             break;
  344.         
  345.         case osEvt:
  346.             DoOSEvent (theEvent);
  347.             break;
  348.             
  349.         case kHighLevelEvent:
  350.             DoHighLevelEvent (theEvent);
  351.             break;
  352.             
  353.         case diskEvt:
  354.             // Put this here just in case the user inserts an unformated disk. 
  355.             if ( HiWord(theEvent->message) != noErr ) {
  356.                 SetPt(&aPoint, kDILeft, kDITop);            // TopLeft of DI dialog.
  357.                 err = DIBadMount(aPoint, theEvent->message);
  358.             }
  359.             break;
  360.     }
  361. }
  362.  
  363.  
  364. #pragma segment Main
  365. void    DoMouseDown (const EventRecord *theEvent)
  366. {
  367.     short        part;
  368.     WindowPtr    theWindow;
  369.     long        menuResult;
  370.     
  371.     part = FindWindow(theEvent->where, &theWindow);
  372.     switch ( part ) {
  373.         case inMenuBar:
  374.             AdjustMenus();
  375.             if (menuResult = MenuSelect(theEvent->where))
  376.                 DoMenuCommand(menuResult, theEvent->modifiers);
  377.             else
  378.                 DoDisabledMenu();
  379.             break;
  380.             
  381.         case inSysWindow:
  382.             SystemClick(theEvent, theWindow);
  383.             break;
  384.             
  385.         case inContent:
  386.             if ( theWindow != FrontWindow() ) {
  387.                 SelectWindow(theWindow);
  388.             } else
  389.                 DoContentClick (theWindow, theEvent);
  390.             break;
  391.             
  392.         case inDrag:        // pass screenBits.bounds to get all gDevices
  393.             if (!(theEvent->modifiers & cmdKey))    // if command key isn't down
  394.                 SelectWindow (theWindow);
  395.                 
  396.             DragWindow(theWindow, theEvent->where, &qd.screenBits.bounds);
  397.             break;
  398.             
  399.         case inGoAway:
  400.             if ( TrackGoAway(theWindow, theEvent->where) )
  401.                 HideWindow (theWindow);
  402.             break;
  403.             
  404.         case inGrow:
  405.             DoGrowWindow (theWindow, theEvent);
  406.             break;
  407.             
  408.         case inZoomIn:
  409.         case inZoomOut:
  410.             if ( TrackBox (theWindow, theEvent->where, part) )
  411.                 DoZoomWindow (theWindow, part);
  412.             break;
  413.     }
  414. }
  415.  
  416.  
  417. #pragma segment Main
  418. void    DoMouseUp (const EventRecord *theEvent)
  419. {
  420. #pragma unused (theEvent)
  421. }
  422.  
  423.  
  424. #pragma segment Main
  425. void    DoActivate (WindowPtr theWindow, Boolean becomingActive)
  426. {
  427. #pragma unused (theWindow, becomingActive)
  428. }
  429.  
  430.  
  431. #pragma segment Main
  432. void    DoUpdate (const EventRecord *theEvent)
  433. {
  434.     WindowPtr    theWindow = (WindowPtr) theEvent->message;
  435.     
  436.     BeginUpdate(theWindow);    
  437.     if ( ! EmptyRgn(theWindow->visRgn) )
  438.     {
  439.     }
  440.     EndUpdate(theWindow);
  441. }
  442.  
  443.  
  444. #pragma segment Main
  445. void    DoOSEvent (const EventRecord *theEvent)
  446. {
  447.     Boolean doConvert;
  448.     unsigned char evType;
  449.  
  450.     evType = (unsigned char) (theEvent->message >> 24) & 0x00ff; // Get the high byte.
  451.     switch (evType) {                     // The high byte of message is the type of event.
  452.         case mouseMovedMessage :
  453.             DoIdle();
  454.             break;
  455.             
  456.         case suspendResumeMessage :
  457.             doConvert = (theEvent->message & convertClipboardFlag) != 0;
  458.             gInBackground = (theEvent->message & resumeFlag) == 0;
  459.             
  460.             if (gInBackground)
  461.               DoSuspend (doConvert);
  462.             else DoResume (doConvert);
  463.             break;
  464.     }
  465. }
  466.  
  467.  
  468. #pragma segment Main
  469. void     DoSuspend(Boolean doClipConvert)
  470. {
  471. #pragma unused (doClipConvert)
  472.  
  473.     DoActivate (FrontWindow(), false);
  474. }
  475.  
  476.  
  477. #pragma segment Main
  478. void     DoResume(Boolean doClipConvert)
  479. {
  480. #pragma unused (doClipConvert)
  481.  
  482.     InitCursor ();
  483.     DoActivate (FrontWindow(), true);
  484. }
  485.  
  486.  
  487. #pragma segment Main
  488. void    DoHighLevelEvent (const EventRecord *theEvent)
  489. {
  490.     OSErr    errCode = noErr;
  491.     
  492.     switch (theEvent->message) {
  493.         default :
  494.             errCode = AEProcessAppleEvent (theEvent);
  495.     }
  496. }
  497.  
  498.  
  499. #pragma segment Main
  500. OSErr    GotRequiredParams (const AppleEvent * theAppleEvent)
  501. {
  502.     DescType    returnedType;
  503.     Size        actualSize;
  504.     OSErr        errCode = noErr;
  505.     
  506.     errCode = AEGetAttributePtr (theAppleEvent, keyMissedKeywordAttr, typeWildCard,
  507.                 &returnedType, nil, 0, &actualSize);
  508.     
  509.     if (errCode == errAEDescNotFound)
  510.         errCode = noErr;
  511.     else if (errCode == noErr)
  512.         errCode = errAEEventNotHandled;
  513.         
  514.     return (errCode);
  515. }
  516.  
  517.  
  518. #pragma segment Main
  519. pascal OSErr    DoAEOpenApplication (const AppleEvent *theAppleEvent, const AppleEvent *reply, long refcon)
  520. {
  521. #pragma unused (reply, refcon)
  522.  
  523.     OSErr    errCode = noErr;
  524.  
  525.     if ((errCode = GotRequiredParams (theAppleEvent)) == noErr)
  526.         DoNew ();
  527.  
  528.     return (errCode);
  529. }
  530.  
  531.  
  532. #pragma segment Main
  533. pascal OSErr    DoAEOpenDocuments (const AppleEvent *theAppleEvent, const AppleEvent *reply, long refcon)
  534. {
  535. #pragma unused (reply, refcon)
  536.  
  537.     OSErr        errCode = noErr;
  538.     FSSpec        fileSpec;
  539.     AEDescList    docList;
  540.     long        index, itemsInList;
  541.     Size        actualSize;
  542.     AEKeyword    keywd;
  543.     DescType    returnedType;
  544.  
  545.     errCode = AEGetParamDesc (theAppleEvent, keyDirectObject, typeAEList, &docList);
  546.     if (errCode == noErr)
  547.     {
  548.         if ((errCode = GotRequiredParams (theAppleEvent)) == noErr)
  549.         {
  550.             (void) AECountItems (&docList, &itemsInList);
  551.             
  552.             for (index = 1; index <= itemsInList; ++index)
  553.             {
  554.                 errCode = AEGetNthPtr (&docList, index, typeFSS, &keywd, &returnedType,
  555.                             (Ptr) &fileSpec, sizeof(fileSpec), &actualSize);
  556.                 
  557.                 if (errCode == noErr)
  558.                     OpenFile (&fileSpec);
  559.                 else
  560.                     PutLine (gLogWindow, "### AEGetNthPtr fails : %d", errCode);
  561.             }
  562.         }
  563.     }
  564.     
  565.     (void) AEDisposeDesc (&docList);
  566.  
  567.     return (errCode);
  568. }
  569.  
  570.  
  571. #pragma segment Main
  572. pascal OSErr    DoAEPrintDocuments (const AppleEvent *theAppleEvent, const AppleEvent *reply, long refcon)
  573. {
  574. #pragma unused (reply, refcon)
  575.  
  576.     OSErr        errCode = noErr;
  577.     FSSpec        fileSpec;
  578.     AEDescList    docList;
  579.     long        index, itemsInList;
  580.     Size        actualSize;
  581.     AEKeyword    keywd;
  582.     DescType    returnedType;
  583.  
  584.     errCode = AEGetParamDesc (theAppleEvent, keyDirectObject, typeAEList, &docList);
  585.     if (errCode == noErr)
  586.     {
  587.         if ((errCode = GotRequiredParams (theAppleEvent)) == noErr)
  588.         {
  589.             (void) AECountItems (&docList, &itemsInList);
  590.             
  591.             for (index = 1; index <= itemsInList; ++index)
  592.             {
  593.                 errCode = AEGetNthPtr (&docList, index, typeFSS, &keywd, &returnedType,
  594.                             (Ptr) &fileSpec, sizeof(fileSpec), &actualSize);
  595.                 
  596.                 if (errCode == noErr)
  597.                     PrintFile (&fileSpec);
  598.                 else
  599.                     PutLine (gLogWindow, "### AEGetNthPtr fails : %d", errCode);
  600.             }
  601.         }
  602.     }
  603.     
  604.     (void) AEDisposeDesc (&docList);
  605.  
  606.     return (errCode);
  607. }
  608.  
  609.  
  610. #pragma segment Main
  611. pascal OSErr    DoAEQuitApplication(const AppleEvent *theAppleEvent, const AppleEvent *reply, long refcon)
  612. {
  613. #pragma unused (reply, refcon)
  614.  
  615.     OSErr    errCode;
  616.     
  617.     if ((errCode = GotRequiredParams (theAppleEvent)) == noErr)
  618.     {
  619.         if (CancelTerminate ())
  620.             errCode = userCanceledErr;
  621.     }
  622.  
  623.     return (errCode);
  624. }
  625.  
  626.  
  627. #pragma segment Main
  628. void DoGrowWindow(WindowPtr theWindow, const EventRecord * theEvent)
  629. {
  630.     long        growResult;
  631.     Rect        growRect;
  632.     WindowPtr    savedPort;
  633.     
  634.     growRect = qd.screenBits.bounds;
  635.     growRect.left = kMinWindowWidth;
  636.     growRect.top = kMinWindowHeight;
  637.     
  638.     growResult = GrowWindow(theWindow, theEvent->where, &growRect);
  639.     
  640.     if ( growResult != 0 ) {
  641.  
  642.         SizeWindow (theWindow, LoWord(growResult), HiWord(growResult), true);
  643.         
  644.         GetPort (&savedPort);
  645.         SetPort (theWindow);
  646.         InvalRect (&theWindow->portRect);
  647.         SetPort (savedPort);
  648.     }
  649. }
  650.  
  651.  
  652. #pragma segment Main
  653. void DoZoomWindow(WindowPtr theWindow, short part)
  654. {
  655. #pragma unused (theWindow, part)
  656. }
  657.  
  658.  
  659. #pragma segment Main
  660. void     DoContentClick (WindowPtr theWindow, const EventRecord * theEvent)
  661. {
  662. #pragma unused (theWindow, theEvent)
  663. }
  664.  
  665.  
  666. #pragma segment Main
  667. void DoDisabledMenu(void)
  668. {
  669.     const    long * kMenuDisable = (long *) 0xB54;
  670.     
  671.     long     menuResult;
  672.     short    menuID;                // resource ID of the selected menu
  673.     short    menuItem;            // item number of the selected menu
  674.     
  675.     if (TrapAvailable (_MenuChoice))
  676.         menuResult = MenuChoice();
  677.     else
  678.         menuResult = *(kMenuDisable);
  679.         
  680.     menuID = HiWord(menuResult);
  681.     menuItem = LoWord(menuResult);
  682.     
  683.     HiliteMenu (menuID);        // This explicit call is necessary since menu was
  684.                                 //        already unhilited by the system at this point.
  685.     switch ( menuID ) {
  686.     }
  687.     HiliteMenu (0);
  688. }
  689.  
  690.  
  691. #pragma segment Main
  692. void DoMenuCommand(long menuResult, short modifiers)
  693. {
  694.     short        menuID;                // resource ID of the selected menu
  695.     short        menuItem;            // item number of the selected menu
  696.     Str255        daName;
  697.     short        daRefNum;
  698.     Boolean        handledByDA;
  699.     WindowPtr    tWindow;
  700.     Boolean        wasHandled = false;
  701.     
  702.     menuID = HiWord(menuResult);
  703.     menuItem = LoWord(menuResult);
  704.     
  705.     if (gTelWindow && gTelWindow->fTELHandle)
  706.         wasHandled = TELMenu (gTelWindow->fTELHandle, menuID, menuItem);
  707.     
  708.     if (!wasHandled)
  709.     {
  710.         switch ( menuID ) {
  711.             case rAppleMenu:
  712.                 switch ( menuItem ) {
  713.                     case iAbout:
  714.                         DoAbout ();
  715.                         break;
  716.                         
  717.                     default:            // Let system handle all Apple Menu Items
  718.                         GetItem(GetMHandle(rAppleMenu), menuItem, daName);
  719.                         daRefNum = OpenDeskAcc(daName);
  720.                         break;
  721.                 }
  722.                 break;
  723.                 
  724.             case rFileMenu:
  725.                 switch ( menuItem ) {
  726.                     case iClose:
  727.                         if (tWindow = FrontWindow())
  728.                             HideWindow (tWindow);
  729.                         break;
  730.                         
  731.                     case iQuit:
  732.                         if (CancelTerminate ())
  733.                             ;
  734.                         break;
  735.                 }
  736.                 break;
  737.                 
  738.             case rEditMenu:
  739.                 handledByDA = SystemEdit(menuItem - 1);
  740.                 break;
  741.                 
  742.             case rWindowMenu:
  743.                 switch ( menuItem ) {
  744.                     case iShowTerm :
  745.                         ShowWindow ((WindowPtr) gTelWindow);
  746.                         SelectWindow ((WindowPtr) gTelWindow);
  747.                         break;
  748.                         
  749.                     case iShowModule :
  750.                         ShowWindow ((WindowPtr) gModuleWindow);
  751.                         SelectWindow ((WindowPtr) gModuleWindow);
  752.                         break;
  753.                         
  754.                     case iShowLog :
  755.                         ShowWindow ((WindowPtr) gLogWindow);
  756.                         SelectWindow ((WindowPtr) gLogWindow);
  757.                         break;
  758.                         
  759.                     case iClearLog :
  760.                         ClearLogWindow (gLogWindow);
  761.                         break;
  762.                 }
  763.                 break;
  764.     
  765.             case rTestMenu:
  766.                 switch ( menuItem ) {
  767.                     case iAnyModule :
  768.                         ExecuteAnyModule ();
  769.                         break;
  770.                         
  771.                     case iChangeDir :
  772.                         if (GetNewTestDirAlias (gModuleWindow))
  773.                             (void) CreateNameList (gModuleWindow);
  774.                         break;
  775.                 }
  776.                 break;
  777.     
  778.             case rFeatureMenu:
  779.                 HandleFeatureMenu (gTelWindow, menuID, menuItem, modifiers);
  780.                 break;
  781.     
  782.             case rInfoMenu:
  783.                 HandleInfoMenu (menuID, menuItem);
  784.                 break;
  785.     
  786.             case rHandlerMenu:
  787.                 HandleHandlerMenu (menuID, menuItem);
  788.                 break;
  789.         }
  790.     }
  791.     HiliteMenu(0);                // Unhighlight what MenuSelect (or MenuKey) hilited.
  792. }
  793.  
  794.  
  795. #pragma segment Main
  796. void    HandleInfoMenu (short menuID, short menuItem)
  797. {
  798. #pragma unused (menuID)
  799.     
  800.     OSErr            errCode = noErr;
  801.     WindowPtr        theWindow = FrontWindow ();
  802.     
  803.     switch (menuItem) {
  804.         case iDumpCAState     :
  805.             DumpCAState (((CAWindowPtr) theWindow)->fCAHandle);
  806.             break;
  807.             
  808.         case iDumpCAInfo    :
  809.             DumpCAInfo (((CAWindowPtr) theWindow)->fCAHandle);
  810.             break;
  811.             
  812.         case iDumpCAEvents    :
  813.             DumpCAEvents ((*((CAWindowPtr) theWindow)->fCAHandle)->hTELDN);
  814.             break;
  815.             
  816.         case iDumpCAFlags    :
  817.             DumpCAFlags (((CAWindowPtr) theWindow)->fCAHandle);
  818.             break;
  819.             
  820.         case iDumpDNInfo    :
  821.             DumpDNInfo (((DNWindowPtr) theWindow)->fDNHandle);
  822.             break;
  823.             
  824.         case iDumpDNEvents    :
  825.             DumpDNEvents (((DNWindowPtr) theWindow)->fDNHandle);
  826.             break;
  827.             
  828.         case iDumpDNFlags    :
  829.             DumpDNFlags (((DNWindowPtr) theWindow)->fDNHandle);
  830.             break;
  831.             
  832.         case iDumpTermInfo    :
  833.             DumpTermInfo (gTelWindow);
  834.             break;
  835.             
  836.         case iDumpTermEvents:
  837.             DumpTermEvents (gTelWindow);
  838.             break;
  839.     }
  840. }
  841.  
  842.  
  843. #pragma segment Main
  844. void    HandleHandlerMenu (short menuID, short menuItem)
  845. {
  846. #pragma unused (menuID)
  847.     
  848.     OSErr            errCode = noErr;
  849.     WindowPtr        theWindow = FrontWindow ();
  850.     
  851.     switch (menuItem) {
  852.         case iInstallAllCA     :
  853.             errCode = TELCAMsgHand (((DNWindowPtr) theWindow)->fDNHandle, telAllCAMsgs, gAllCAMsgsHandlerUPP, SetCurrentA5());
  854.             if (errCode == noErr)
  855.                 PutLine (gLogWindow, "gAllCAMsgsHandlerUPP is installed");
  856.             else
  857.                 PutCLine (gLogWindow, kErrorColor, "### TELCAMsgHand fails : %d", errCode);
  858.             break;
  859.             
  860.         case iRemoveAllCA     :
  861.             errCode = TELClrCAMsgHand (((DNWindowPtr) theWindow)->fDNHandle, gAllCAMsgsHandlerUPP);
  862.             if (errCode == noErr)
  863.                 PutLine (gLogWindow, "gAllCAMsgsHandlerUPP is removed");
  864.             else
  865.                 PutCLine (gLogWindow, kErrorColor, "### TELClrCAMsgHand fails : %d", errCode);
  866.             break;
  867.             
  868.         case iInstallAllDN     :
  869.             errCode = TELDNMsgHand (((DNWindowPtr) theWindow)->fDNHandle, false, telAllDNMsgs, gAllDNMsgsHandlerUPP, SetCurrentA5());
  870.             if (errCode == noErr)
  871.                 PutLine (gLogWindow, "gAllDNMsgsHandlerUPP is installed");
  872.             else
  873.                 PutCLine (gLogWindow, kErrorColor, "### TELDNMsgHand fails : %d", errCode);
  874.             break;
  875.             
  876.         case iRemoveAllDN     :
  877.             errCode = TELClrDNMsgHand (((DNWindowPtr) theWindow)->fDNHandle, gAllDNMsgsHandlerUPP);
  878.             if (errCode == noErr)
  879.                 PutLine (gLogWindow, "gAllDNMsgsHandlerUPP is removed");
  880.             else
  881.                 PutCLine (gLogWindow, kErrorColor, "### TELClrDNMsgHand fails : %d", errCode);
  882.             break;
  883.             
  884.         case iInstallAllTerm:
  885.             errCode = TELTermMsgHand (((TelWindowPtr) theWindow)->fTELHandle, telAllTermMsgs, gAllTermMsgsHandlerUPP, SetCurrentA5());
  886.             if (errCode == noErr)
  887.                 PutLine (gLogWindow, "gAllTermMsgsHandlerUPP is installed");
  888.             else
  889.                 PutCLine (gLogWindow, kErrorColor, "### TELTermMsgHand fails : %d", errCode);
  890.             break;
  891.             
  892.         case iRemoveAllTerm    :
  893.             errCode = TELClrTermMsgHand (((TelWindowPtr) theWindow)->fTELHandle, gAllTermMsgsHandlerUPP);
  894.             if (errCode == noErr)
  895.                 PutLine (gLogWindow, "gAllTermMsgsHandlerUPP is removed");
  896.             else
  897.                 PutCLine (gLogWindow, kErrorColor, "### TELClrTermMsgHand fails : %d", errCode);
  898.             break;
  899.     }
  900. }
  901.  
  902.  
  903. #pragma segment Main
  904. Boolean    WrongEnvironment (void)
  905. {
  906.     long    response;
  907.     OSErr    errCode = Gestalt (gestaltSystemVersion, &response);
  908.     
  909.     if (errCode != noErr) {
  910.         AlertUser ("\pGestalt fails !", errCode);
  911.         return (true);
  912.     }
  913.     
  914.     if (response < 0x700) {
  915.         AlertUser ("\pStiletto requires system 7 or later.", response);
  916.         return (true);
  917.     }
  918.     
  919.     return (false);
  920. }
  921.  
  922.  
  923. #pragma segment Main
  924. void    DoNew (void)
  925. {
  926. }
  927.  
  928.  
  929. #pragma segment Main
  930. void    OpenFile (FSSpecPtr theFile)
  931. {
  932.     ExecuteModule (theFile);
  933. }
  934.  
  935.  
  936. #pragma segment Main
  937. void    PrintFile (FSSpecPtr theFile)
  938. {
  939. #pragma unused (theFile)
  940. }
  941.  
  942.  
  943. #pragma segment Main
  944. Boolean    CancelTerminate (void)
  945. {
  946.     /**
  947.      **        Check if user intends to cancel quiting.
  948.      **        If quiting is no longer desired, return true
  949.      **        else call Terminate() to do some cleanup & return false.
  950.      **/
  951.     
  952.     Terminate ();
  953.     
  954.     return (false);
  955. }
  956.  
  957.  
  958. #pragma segment Main
  959. main ()
  960. {
  961.     Rect    logWindowRect;
  962.     Rect    telWindowRect;
  963.     Rect    moduleWindowRect;
  964.     
  965.     UnloadSeg ((Ptr) _DataInit);        // Don't need this any more (UnloadSeg unsupported on PowerPC)
  966.  
  967.     MaxApplZone();                        // Ask for all the memory allowed for this app.
  968.     
  969.     MoreMasters();                        // We hate memory fragmentation, so make sure
  970.     MoreMasters();                        //    we have enough master pointers.
  971.     MoreMasters();
  972.     MoreMasters();
  973.     
  974.     GetWinLocFromPref (&logWindowRect, rLogWindRECT);
  975.     GetWinLocFromPref (&telWindowRect, rTelWindRECT);
  976.     GetWinLocFromPref (&moduleWindowRect, rModuleWindRECT);
  977.     
  978.     if (Initialize () == noErr)            // Initialize Mac managers and display the menu bar.
  979.     {
  980.         if (! WrongEnvironment ()) 
  981.         {
  982.             if (CreateLogWindow (&gLogWindow, &logWindowRect) == noErr)
  983.             {
  984.  
  985. #ifdef __powerc
  986.                 PutLine (gLogWindow, "Running in PPC native mode");
  987. #else
  988.                 PutLine (gLogWindow, "Running in 68K native mode");
  989. #endif
  990.  
  991.                 if (InitCTBManagers () == noErr)
  992.                 {
  993.                     if (CreateModuleWindow (&gModuleWindow, &moduleWindowRect) == noErr)
  994.                     {
  995.                         if (CreateTelWindow (&gTelWindow, &telWindowRect, nil) == noErr)
  996.                         {
  997.                             UnloadSeg ((Ptr) Initialize);
  998.                             
  999.                             InitializedAppleEvents ();
  1000.                             
  1001.                             LoopTheLoop ();                // Off we go into the loop of doom.
  1002.                         }
  1003.                     }
  1004.                 }
  1005.             }
  1006.         }
  1007.     }
  1008. }
  1009.